﻿using System.Diagnostics;
using System.IO;

namespace TranscoderAxisMJPEG {
    public class AxisMJPEG {
        /// <summary>
        /// transcode all files of source folder to .h264 
        /// save the transcoded files in destination folder
        /// </summary>
        /// <param name="executeFile"> path to the ffmpeg.exe file</param>
        /// <param name="sourceFolder">.asf files folder</param>
        /// <param name="desFolder">.h264 files folder</param>
        public void TranscodeMJPEG(string executeFile, string sourceFolder, string desFolder) {
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.ErrorDialog = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.FileName = executeFile;         // "E:\\ffmpeg.exe";
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(sourceFolder);
            int count = dir.GetFiles().Length;
            string[] filePaths = System.IO.Directory.GetFiles(sourceFolder);
            for (int n = 0; n < count; n++) {
                string fileName = Path.GetFileNameWithoutExtension(filePaths[n]);
                p.StartInfo.Arguments = @"-i " + "  " + filePaths[n] + "   " + desFolder + fileName + ".h264";
                p.Start();
            }

        }
    }
}
